<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Using Phar Archives: the phar stream wrapper</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="phar.using.intro.html">« Using Phar Archives: Introduction</a></li>
      <li style="float: right;"><a href="phar.using.object.html">Using Phar Archives: the Phar and PharData class »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="phar.using.html">Using Phar Archives</a></li>
    <li>Using Phar Archives: the phar stream wrapper</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="phar.using.stream" class="section">
 <h2 class="title">Using Phar Archives: the phar stream wrapper</h2>
 <p class="para">
  The Phar stream wrapper fully supports <span class="function"><a href="function.fopen.html" class="function">fopen()</a></span> for
  read and write (not append), <span class="function"><a href="function.unlink.html" class="function">unlink()</a></span>, <span class="function"><a href="function.stat.html" class="function">stat()</a></span>,
  <span class="function"><a href="function.fstat.html" class="function">fstat()</a></span>, <span class="function"><a href="function.fseek.html" class="function">fseek()</a></span>, <span class="function"><a href="function.rename.html" class="function">rename()</a></span>
  and directory stream operations <span class="function"><a href="function.opendir.html" class="function">opendir()</a></span> and <span class="function"><a href="function.rmdir.html" class="function">rmdir()</a></span>
  and <span class="function"><a href="function.mkdir.html" class="function">mkdir()</a></span>.
 </p>
 <p class="para">
  Individual file compression and per-file metadata can also be manipulated
  in a Phar archive using stream contexts:
 </p>
 <p class="para">
  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$context&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stream_context_create</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'phar'&nbsp;</span><span style="color: #007700">=&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">'compress'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">GZ</span><span style="color: #007700">)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">'metadata'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(</span><span style="color: #DD0000">'user'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'cellog'</span><span style="color: #007700">)));<br /></span><span style="color: #0000BB">file_put_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'phar://my.phar/somefile.php'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$context</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </p>
 <p class="para">
  The <code class="literal">phar</code> stream wrapper does not operate on remote files,
  and cannot operate on remote files, and so is allowed even when the
  <a href="filesystem.configuration.html#ini.allow-url-fopen" class="link">allow_url_fopen</a> and
  <a href="filesystem.configuration.html#ini.allow-url-include" class="link">allow_url_include</a> INI options
  are disabled.
 </p>
 <p class="para">
  Although it is possible to create phar archives from scratch just using
  stream operations, it is best to use the functionality built into
  the Phar class.  The stream wrapper is best used for read-only operations.
 </p>
</div></div></div></body></html>